home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / asm / utils / mouse / mouse.asm < prev    next >
Assembly Source File  |  1980-01-03  |  5KB  |  226 lines

  1. ;
  2. ; ### Mouse v 1.25 ###
  3. ;
  4. ; - Created 881021 by TM -
  5. ;
  6. ;
  7. ; NOTES:
  8. ;
  9. ;
  10. ; BUGS:
  11. ;
  12. ; - None, I hope
  13. ;
  14. ;
  15. ; Edited:
  16. ;
  17. ; - 881217 by TM -> v0.60    - Code compressed from 1408 to 900 bytes.
  18. ; - 881217 by JM -> v0.80    - Code compressed from 900 to 724 bytes.
  19. ; - 881217 by JM -> v1.00    - Code commented and compressed to 720 bytes.
  20. ; - 881224 by JM -> v1.10    - Some structure offsets changed to labels.
  21. ;                - Executable now 716 bytes.
  22. ; - 881224 by JM -> v1.15    - Crunching, version id added.
  23. ;                  Executable 688 bytes only.
  24. ; - 881225 by JM -> v1.20    - A bug fixed with NEWLIST macro.  Executable
  25. ;                  692 bytes.
  26. ; - 881227 by JM -> v1.25    - LN_PRI and LN_NAME set to NULL.  Executable
  27. ;                  700 bytes.
  28. ;
  29. ;
  30.  
  31.         include    "jmplibs.i"
  32.         include    "exec/types.i"
  33.         include    "exec/nodes.i"
  34.         include    "exec/lists.i"
  35.         include    "exec/ports.i"
  36.         include    "exec/io.i"
  37.         include    "devices/input.i"
  38.         include    "com.i"
  39.         include    "exec.xref"
  40.         include    "dos.xref"
  41.         include    "relative.i"
  42.         include    "string.i"
  43.         include    "intuition.xref"
  44.  
  45. RELATIVE     equ    -1            allocates memory from stack
  46.  
  47.  
  48. *
  49. * Variables allocated from stack:
  50. *
  51.  
  52.         .var
  53.         dl    _DosBase,_IntuitionBase
  54.         dl    cmdbuf
  55.         dl    ODerror,ASerror
  56.         dw    mouseport
  57.         da    iorequest,48
  58.         da    msgport,34
  59.         da    prefs,128
  60.  
  61.  
  62. start        .begin
  63.         move.l    a0,cmdbuf(a4)        start of command line buffer
  64.         clr.b    -1(a0,d0.w)
  65.  
  66.         openlib    Dos,clean        open libraries
  67.         openlib    Intuition,clean
  68.  
  69.         lea    prefs(a4),a0        get current Preferences settings
  70.         moveq    #116,d0
  71.         lib    Intuition,GetPrefs
  72.  
  73.         move.l    cmdbuf(a4),a5        check if info needed
  74.         move.b    (a5),d0
  75.         cmp.b    #'?',d0            '?' -> print usage
  76.         beq    info
  77.         tst.b    d0
  78.         bne.s    mowlawn            command not empty -> jump
  79.  
  80.         lea    tcmsi(pc),a0        if cmdline is empty...
  81.         lea    prefs(a4),a1        ...output current mouse speed
  82.         move.w    108(a1),d0        current speed from Preferences
  83.         cmp.w    #9,d0
  84.         bhi.s    msunkwn            more than 9 -> output other msg
  85.         lea    speedy(pc),a1
  86.         or.b    d0,(a1)            store speed into buffer
  87.         bra.s    eclean            ...and print string
  88.  
  89. msunkwn        lea    mt9(pc),a0        mouse is very slow!
  90.         bra.s    eclean
  91.  
  92. mowlawn        bsr    skipblk            change settings
  93.         move.b    (a5)+,d0
  94.         beq    clean
  95.         bsr    ucase
  96. mowwell        cmp.b    #'0',d0            check if speed in allowed range
  97.         blo.s    mow1
  98.         cmp.b    #'9',d0
  99.         bhi.s    mow1
  100.         and.w    #15,d0            convert to binary
  101.         lea    prefs(a4),a0
  102.         move.w    d0,108(a0)        write new speed into structure
  103.         moveq    #116,d0
  104.         moveq    #-1,d1
  105.         lib    Intuition,SetPrefs    set mouse speed
  106.         addq.l    #1,a5
  107.         bra.s    mowlawn
  108.  
  109. mow1        cmp.b    #'S',d0            S command
  110.         bne.s    mow2
  111.         bsr    skipblk
  112.         move.b    (a5)+,d0
  113.         beq.s    info
  114.         bra.s    mowwell
  115.  
  116. mow2        cmp.b    #'P',d0            set port - P command
  117.         bne.s    info
  118.         bsr    skipblk
  119.         move.b    (a5)+,d0
  120.         sub.b    #'1',d0            check if port 1 or 2
  121.         blo.s    info
  122.         cmp.b    #1,d0
  123.         bhi.s    info
  124.         bsr    mport            set port in subrtn
  125.         bra.s    mowlawn
  126.  
  127.  
  128. info        lea    infotxt(pc),a0        print info text
  129. eclean        printa    a0            print message
  130. clean        closlib    Intuition        close libraries
  131.         closlib    Dos
  132.         moveq.l    #0,d0
  133.         .end
  134.  
  135.  
  136. skipblk        move.b    (a5)+,d0        skip blank (SPC/TAB)
  137.         cmp.b    #' ',d0
  138.         beq.s    skipblk
  139.         cmp.b    #9,d0
  140.         beq.s    skipblk
  141.         subq.w    #1,a5
  142.         rts
  143.  
  144. ucase        cmp.b    #'a',d0            convert a char to UPPER CASE
  145.         blo.s    ucase1
  146.         cmp.b    #'z',d0
  147.         bhi.s    ucase1
  148.         sub.b    #$20,d0
  149. ucase1        rts
  150.  
  151.  
  152. *
  153. * This routine sets the mouse port. D0 must contain 0 or 1 for port
  154. * 1 or 2, respectively.
  155. *
  156.  
  157. mport        move.b    d0,mouseport(a4)
  158.         lea    indevname(pc),a0    input.device
  159.         moveq.l    #0,d0            unit#
  160.         lea    iorequest(a4),a1    IoReq
  161.         moveq.l    #0,d1            flags
  162.         lib    Exec,OpenDevice        open input.device
  163.         move.l    d0,ODerror(a4)        error -> ODerror != 0
  164.         bne.s    mpclean            if error
  165.  
  166.         lea    msgport(a4),a2
  167.         move.b    #NT_MSGPORT,LN_TYPE(a2)    node type = messageport
  168.         clr.b    LN_PRI(a2)        priority = 0
  169.         clr.l    LN_NAME(a2)        no name
  170.         clr.b    MP_FLAGS(a2)        Flags = 0
  171.  
  172.  
  173.         moveq.l    #-1,d0            get a signal bit
  174.         move.l    d0,ASerror(a4)
  175.         flib    Exec,AllocSignal
  176.         move.l    d0,ASerror(a4)        signal bit number or error
  177.         bmi.s    mpclean
  178.  
  179.         move.b    d0,MP_SIGBIT(a2)    set signal bit number
  180.  
  181.         sub.l    a1,a1
  182.         flib    Exec,FindTask        find this task
  183.         move.l    d0,MP_SIGTASK(a2)    set task pointer
  184.  
  185.         lea    MP_MSGLIST(a2),a0
  186.         NEWLIST    a0            NewList(list) (macro)
  187.  
  188.         move.l    a2,d0
  189.         lea    iorequest(a4),a2
  190.         move.l    d0,MN_REPLYPORT(a2)    set reply port pointer
  191.  
  192.         move.w    #IND_SETMPORT,IO_COMMAND(a2) set io_Command
  193.         lea    mouseport(a4),a0
  194.         move.l    a0,IO_DATA(a2)        io_Data = &mouseport
  195.         moveq.l    #1,d0
  196.         move.l    d0,IO_LENGTH(a2)    io_Length = 1
  197.  
  198.         move.l    a2,a1
  199.         flib    Exec,DoIO        set mouseport
  200.  
  201. mpclean        move.l    ODerror(a4),d0        test if input.device open
  202.         bne.s    mpclea1            no -> don't try to close it
  203.         lea    iorequest(a4),a1
  204.         flib    Exec,CloseDevice    close input.device
  205.  
  206. mpclea1        move.l    ASerror(a4),d0        test if a signal allocated
  207.         bmi.s    mpclea2            no -> don't try to free it
  208.         flib    Exec,FreeSignal        free signal
  209.  
  210. mpclea2        rts
  211.  
  212.  
  213.  
  214. infotxt        dc.b    'Mouse v1.25',10
  215.         dc.b    'Usage: mouse [P <port>] [[S] <speed>]',10,0
  216. indevname    dc.b    'input.device',0
  217. mt9        dc.b    'more than 9',10,0
  218. tcmsi        dc.b    'The current mouse speed is '
  219. speedy        dc.b    '0.',10,0
  220.  
  221.  
  222.         libnames
  223.  
  224.         end
  225.  
  226.